<?php
namespace app\admin\controller;
use app\common\controller\AdminBase;
use app\admin\model\AdminMenu;

/**
 * 菜单管理
 */
class Menu extends AdminBase
{
    /**
     * 菜单分类
     */
    public function index()
    {
        $model = new AdminMenu();
        $param = $this->request->param();
        if(!empty($param['keyword'])){
            $model = $model->where('title','like','%'.$param['keyword'].'%');
        }
        $lists = $model->order('sort_order asc,id asc')->select();
        $this->result($lists);
    }

    /**
     * 编辑菜单
     */
    public function edit()
    {
        if ($this->request->isPost()) {
            $param = $this->request->param();
            $model = new AdminMenu();
            if(!empty($param['id'])){
                unset($param['create_time']);
                $model = AdminMenu::find($param['id']);
            }
            $result = $model->save($param);
            $this->result([],0,'操作成功');
        }
    }

    /**
     * 删除字典
     */
    public function del()
    {
        if ($this->request->isPost()) {
            $param = $this->request->param();
            AdminMenu::destroy($param['id']);
            $this->result([],0,'删除成功');
        }
    }

}
